<template>
    <div class="login">
        <van-nav-bar
  title="登录"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
/>
<van-cell-group inset>
    <van-field v-model="tel" name="手机号" label="手机号" placeholder="手机号" />
    <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码" />
</van-cell-group>
<div style="margin: 16px;">
    <van-button round block type="primary" @click="loginIn">
        登录
    </van-button>
</div>
</div>
</template>

<script>
import { doDenglu } from '@/api/user';
    export default {
        data(){
            return{
                tel:'',
                password:''
            }
        },
        created(){
            this.tel=localStorage.getItem('tel')
        },
        methods:{
            onClickLeft(){
                history.back()
            },
            loginIn(){
                doDenglu({loginname:this.tel,password:this.password}).then(res=>{
                    console.log(res);
                    if (res.data.code=='10010') {
                        return showToast('用户不存在')
                    }
                    if (res.data.code=='10011') {
                        return showToast('密码错误')
                    }
                    localStorage.setItem('token',res.data.data.token)
                    localStorage.setItem('userid',res.data.data.userid)
                    this.$router.push('/home')
                })
            }
        }
    }
</script>

<style lang="less" scoped>

</style>